<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>        
  </head>
  
  <body>
  	<input type="button" class="btn btn-mini btn-info" value="增  加" id="add">
  	<input type="button" class="btn btn-mini btn-success" value="修  改" id="modify">
  	<input type="button" class="btn btn-mini btn-danger" value="删  除" id="delete">
  	<input type="button" class="btn btn-mini btn-primary" value="设计问卷" id="degin">
  	<input type="button" class="btn btn-mini btn-success" value="复制问卷" id="copy">
  	<input type="button" class="btn btn-mini btn-warning" value="预  览" id="view">
    <div class="accordion-group widget-box">
      <div class="accordion-heading">
        <div class="widget-title"> 
        	<a data-parent="#collapse-group" href="#collapseGOne" data-toggle="collapse" class="collapsed">
         	<span class="icon"><i class="icon-search"></i></span>
          	<h5>检索条件</h5>
          	</a> 
        </div>
      </div>
      <div class="accordion-body in collapse" id="collapseGOne" style="height: auto;">
        <div class="form-horizontal">
        	<div class="control-group">
              <label class="control-label">问卷名称 :</label>
              <div class="controls">
              		<input type="text" placeholder="Survey Name" class="span10" id="survey_name">
              		<div class="button-search-right">
              			<input type="button" class="btn btn-success" value="检  索" id="searchButton">
              		</div>
              </div>
            </div>
        </div>
      </div>
    </div>
    
    <hr />
    <table id="tabGrid"></table>
    <div id="pager"></div>
  </body>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery/jqGridUtil.js"></script>
    <script type="text/javascript">
	    jQuery(function(){	    	
	    	var config = {
	           	url:'<%=request.getContextPath() %>/wjgl/survey/getSurveyList.html',
	           	colModel:[
	           		{label:'id',name:"id",index:'id', key:true ,hidden:true},
	           		{label:'问卷名称',name:"name",index:'name'},
	           		//{label:'问卷总分',name:"totalCore",index:'totalCore',align:"center"},
	           		{label:'创建人',name:"createUser",index:'createUser'},
	           		{label:'创建时间',name:"createTime",index:'createTime'},
	           		{label:'是否启用',name:"usedFlg",index:'usedFlg',align:"center",formatter:'select',editoptions:{value:"0:启用;1:不启用"}},
	           		{label:'counts',name:"counts",index:'counts',hidden:true}
	           	],
	           	table:"#tabGrid",
	           	pager: "#pager",
	           	sortname:"createTime",
	           	sortorder:"desc",
	            caption:"问卷信息列表"
	        };
	    	
	    	
	    	jQuery.loadGrid(config);
	    	
	    	jQuery("#add").bind("click",function(){
	    		showDialog("增加问卷",850,515,"<%=request.getContextPath() %>/wjgl/survey/toAddSurvey.html");
	    	});
	    	
	    	jQuery("#modify").bind("click",function(){
	    		var id = getChecked();
				if(id.length!=1){
					alert("请先选定一条记录!");
					return false;
				}
				
				var row = jQuery("#tabGrid").jqGrid('getRowData', id);
	    		showDialog("修改问卷",850,515,"<%=request.getContextPath() %>/wjgl/survey/toUpdateSurvey.html?id="+row.id);
	    	});
	    	
	    	jQuery("#delete").bind("click",function(){

	    		//选中的行
	         var id = jQuery("#tabGrid").jqGrid('getGridParam', 'selarrrow');
	         for (var i = 0 ; i < id.length ; i++){
							var row = jQuery("#tabGrid").jqGrid('getRowData', id[i]);
							if(row.counts != "0"){
								alert("选择的问卷已有问卷发送记录，不能删除!");
								return false;
							}
	         }
	    		plcz("<%=request.getContextPath() %>/wjgl/survey/deleteSurvey.html","删除");
	    	});

	    	//复制问卷
	    	jQuery("#copy").bind("click",function(){
		    		var id = getChecked();
						if(id.length!=1){
							alert("请先选定一个要复制的问卷!");
							return false;
						}
						var row = jQuery("#tabGrid").jqGrid('getRowData', id);
						confirm("确定要复制该问卷吗？",function(){

							jQuery.post("<%=request.getContextPath()%>/wjgl/survey/copySurvey.html?",{
								id:row.id
							},function(data){
								alert(data,function(){
									searchResult()
								});
							},"json");
						});
						
	    	});
	    	
	    	jQuery("#degin").bind("click",function(){
	    		var id = getChecked();
				if(id.length!=1){
					alert("请先选定一条记录!");
					return false;
				}
				
				var row = jQuery("#tabGrid").jqGrid('getRowData', id);
	    		showDialog("设计问卷",1000,550,"<%=request.getContextPath() %>/wjgl/survey/toDeginSurvey.html?id="+row.id);
	    	});
	    	
	    	
	    	jQuery("#view").bind("click",function(){
	    		var id = getChecked();
				if(id.length!=1){
					alert("请先选定一条记录!");
					return false;
				}
				
					var row = jQuery("#tabGrid").jqGrid('getRowData', id);
	    		showDialog("预览问卷",1000,550,"<%=request.getContextPath() %>/wjgl/survey/viewSurvey.html?id="+row.id);
	    	});
	    	
	    	jQuery("#searchButton").bind("click",searchResult);
	    	
	    });
	    
	     function searchResult() {
	    	var map = {};
	    	map["name"] = jQuery('#survey_name').val();
				jQuery("#tabGrid").jqGrid('setGridParam',{  
	    	     postData : map
	    	 }).trigger('reloadGrid');
	    }
	    
    </script>
</html>
